import BaseTable from '../BaseTable/BaseTable.vue';
export default {
    name: 'supplement',
    props: ['data'],
    components: {
        BaseTable
    },
    data() {
        return {
            formList: [
                {
                    label: '税率',
                    prop: 'invoiceTaxRate',
                    type: 'select',
                    change: null,
                    options: [
                        { label: '0', value: '1' },
                        { label: '1', value: '2' },
                        { label: '3', value: '3' },
                        { label: '6', value: '4' },
                        { label: '9', value: '5' }
                    ],
                    unit: '%',
                    block: true
                },
                { label: '工程预算总造价', prop: 'projectBudget' },
                {
                    label: '不含税工程预算总造价',
                    prop: 'projectBudgetExceptTax'
                },
                { label: '工程申报总造价', prop: 'declareProjectBudget' },
                {
                    label: '不含税工程申报总造价',
                    prop: 'projectDeclareExceptTax'
                },
                { label: '工程审批总造价', prop: 'examineProjectBudget' },
                { label: '不含税工程审批总造价', prop: 'projectApproveExceptTax' }
            ],
            tableConfig: [
                { prop: 'projectNumber', label: '项目编号', width: '100' },
                { prop: 'projectName', label: '项目名称', width: '100', showTips: true },
                { prop: 'featureDescription', label: '特征描述', width: '100', showTips: true },
                { prop: 'unit', label: '单位', width: '100' },
                {
                    prop: 'covertItem',
                    label: '是否隐藏项',
                    width: '100',
                    formatter(val) {
                        const coverItemMap = { 0: '否', 1: '是' };
                        return coverItemMap[val];
                    }
                },
                {
                    prop: 'quantities',
                    label: '工程量',
                    type: 'input',
                    disabled: true,
                    change: null,
                    width: '100'
                },
                {
                    prop: 'integratedUnitPrice',
                    label: '综合单价',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'totalPrice',
                    label: '综合总价',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'materialsBrand',
                    label: '主材品牌',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'declareQuantities',
                    label: '申报工作量',
                    type: 'input',
                    change: null
                },
                {
                    prop: 'declareTotalPrice',
                    label: '申报综合总价',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'declareMaterialsBrand',
                    label: '申报主材品牌',
                    type: 'select',
                    options: [],
                    width: '100'
                },
                { prop: 'brandExplain', label: '品牌说明', type: 'input' },
                {
                    prop: 'examineQuantities',
                    label: '审核工作量',
                    type: 'input',
                    disabled: true,
                    width: '100'
                },
                {
                    prop: 'examineTotalPrice',
                    label: '审核综合总价',
                    disabled: true,
                    type: 'input',
                    width: '100'
                },
                {
                    prop: 'examineMaterialsBrand',
                    label: '审核主材品牌',
                    disabled: true,
                    type: 'input',
                    width: '100'
                }
            ]
        };
    },
    computed: {
        tableData() {
            const list = this.data.supplementList;
            list &&
                list.forEach(v => {
                    v.options = v.materialsBrand?.split(',');
                });
            return this.data.supplementList;
        }
    },
    mounted() {
        this.initQuantityReact();
        this.initTaxChangeReact();
    },
    methods: {
        // 为工程量、综合单价输入框注册input事件
        initQuantityReact() {
            const vm = this;
            let col = vm.tableConfig.find(v => v.prop === 'examineQuantities');
            col.change = (val, { row, $index }) => {
                const ret = (+row.integratedUnitPrice || 0).mul(+val).toFixed(2);
                vm.data.supplementList[$index].examineTotalPrice = ret;
                vm.$root.$emit('calcTaxRate');
            };
        },
        // 税率切换重新计算总价
        initTaxChangeReact() {
            const vm = this;
            const formItem = this.formList.find(item => item.prop === 'invoiceTaxRate');
            formItem.change = () => {
                vm.$root.$emit('calcTaxRate');
            };
        }
    }
};
